package com.ztjava.common.listener.push;

import org.apache.log4j.Logger;

import com.jfinal.aop.Duang;
import com.jfinal.kit.JsonKit;
import com.jfinal.kit.Ret;
import com.ztjava.common.service.PushService;
import com.ztjava.core.Constant;
import com.ztjava.core.bean.sub.PushBean;
import com.ztjava.plugin.event.EventTag;
import com.ztjava.plugin.event.core.ApplicationListener;
import com.ztjava.plugin.event.core.Listener;
import com.ztjava.plugin.event.core.RequestEvent;

@Listener(enableAsync = true,tag = EventTag.COMMON_PUSH_ASYNC)
public class PushAsyncListener implements ApplicationListener<RequestEvent>{
	private static Logger logger = Logger.getLogger(PushAsyncListener.class);
	private static PushService pushService = Duang.duang(PushService.class);
	@Override
	public Ret onApplicationEvent(RequestEvent event) {
		PushBean pushBean = (PushBean)event.getSource();
		Ret result =  pushService.push(pushBean);
		logger.debug(JsonKit.toJson(pushBean));
		if(result.getStr(Constant.RESULT).equals(Constant.ERROR)){
			logger.error("发送失败:"+result.getStr(Constant.MESSAGE));
			logger.error(JsonKit.toJson(pushBean));
		}
		return result;
	}

}
